package cn.stylefeng.guns.sys.modular.interfaceapproval.controller;

import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.dbServicelist.model.params.DbServicelistParam;
import cn.stylefeng.guns.sys.modular.interfaceapproval.entity.Interfaceapproval;
import cn.stylefeng.guns.sys.modular.interfaceapproval.model.params.InterfaceapprovalParam;
import cn.stylefeng.guns.sys.modular.interfaceapproval.model.result.InterfaceapprovalResult;
import cn.stylefeng.guns.sys.modular.interfaceapproval.service.InterfaceapprovalService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;


/**
 * 接口审批列表控制器
 *
 * @author author
 * @Date 2020-08-31 13:58:32
 */
@Controller
@RequestMapping("/interfaceapproval")
public class InterfaceapprovalController extends BaseController {

    private String PREFIX = "/modular/interfaceapproval/interfaceapproval";

    @Autowired
    private InterfaceapprovalService interfaceapprovalService;

    /**
     * 跳转到主页面
     *
     * @author author
     * @Date 2020-09-01
     */
    @RequestMapping("")
    public String index() {
        int dept = Math.toIntExact(LoginContextHolder.getContext().getUser().getDeptId());
        if (dept != 25){
            return PREFIX + "/interfaceapprovalKH.html";
        }else{
            return PREFIX + "/interfaceapproval.html";
        }
    }

    /**
     * 新增页面
     *
     * @author author
     * @Date 2020-08-31
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/interfaceapproval_add.html";
    }

    /**
     * 管理端接口定制查看详情页面
     *
     * @author author
     * @Date 2020-09-07
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/interfaceapproval_edit.html";
    }

    /**
     * 管理端接口定制完成详情
     * 委办局接口定制完成详情
     *
     * @author author
     * @Date 2020-09-09
     */
    @RequestMapping("/interfaceCustomDone")
    public String interfaceCustomDone() {
        return PREFIX + "/interfaceCustomDone.html";
    }


    /**
     * 管理端数据对比接口查看详情页面
     * 管理端数据对比审批完成详情
     *
     * @author author
     * @Date 2020-09-07
     */
    @RequestMapping("/editComparison")
    public String editComparison() {
        return PREFIX + "/interfaceComparison.html";
    }

    /**
     * 委办局新增接口定制
     *
     * @author author
     * @Date 2020-08-31
     */
    @RequestMapping("/addInterfaceCustom")
    public String interfaceCustom() {
        return PREFIX + "/interfaceCustom.html";
    }

    /**
     * 委办局新增数据对比接口
     *
     * @author author
     * @Date 2020-08-31
     */
    @RequestMapping("/addInterfaceDataCompare")
    public String addInterfaceDataCompare() {
        return PREFIX + "/interfaceDataCompare.html";
    }


    /**
     * 委办局数据对比审批完成查看详情
     *
     * @author author
     * @Date 2020-08-31
     */
    @RequestMapping("/queryInterfaceData")
    public String queryInterfaceData() {
        return PREFIX + "/interfaceDataCpmpareDone.html";
    }


    /**
     * 新增接口
     *
     * @author author
     * @Date 2020-08-31
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(InterfaceapprovalParam interfaceapprovalParam) {
        this.interfaceapprovalService.add(interfaceapprovalParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author author
     * @Date 2020-08-31
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(InterfaceapprovalParam interfaceapprovalParam) {
        this.interfaceapprovalService.update(interfaceapprovalParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author author
     * @Date 2020-08-31
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(InterfaceapprovalParam interfaceapprovalParam) {
        this.interfaceapprovalService.delete(interfaceapprovalParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author author
     * @Date 2020-08-31
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(InterfaceapprovalParam interfaceapprovalParam) {
        Interfaceapproval detail = this.interfaceapprovalService.getById(interfaceapprovalParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author author
     * @Date 2020-08-31
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(InterfaceapprovalParam interfaceapprovalParam) {
        return this.interfaceapprovalService.findPageBySpec(interfaceapprovalParam);
    }

    /**
     * 批准
     *
     * @author author
     * @Date 2020-09-01
     */
    @ResponseBody
    @RequestMapping("/approve")
    public Integer approve(@RequestParam Integer[] ids) {
        Integer reid = 0;
        for (int i = 0; i < ids.length; i++) {
            interfaceapprovalService.updateApprove(ids[i]);
            reid++;
        }
        return reid;
    }


    /**
     * 驳回
     *
     * @author author
     * @Date 2020-09-01
     */
    @ResponseBody
    @RequestMapping("/reject")
    public Integer reject(@RequestParam Integer[] ids) {
        Integer reid = 0;
        for (int i = 0; i < ids.length; i++) {
            interfaceapprovalService.updateReject(ids[i]);
            reid++;
        }
        return reid;
    }
}


